﻿using System;
using NetFramework.Logging.CoreLoggers;
using NetFramework.Setting;
using System.Configuration;

namespace NetFramework.Logging
{
    public static class LoggerManager
    {
        private static ILogger log;

        static LoggerManager()
        {
            LoggerSetting setting = FrameworkConfig.GetLoggerSetting();
            if (setting == null)
            {
                log = new DebugLogger();
            }
            else
            {
                if (setting.Providers == null || setting.Providers.Count == 0)
                {
                    log = new EventLogger();
                }
                else
                {
                    ProviderSettings provider = setting.Providers[0];
                    
                    Type loggerType = Type.GetType(provider.Type);
                    object[] args = {provider.Parameters};

                    try
                    {
                        log = Activator.CreateInstance(loggerType, args) as ILogger;
                    }
                    catch(Exception ex)
                    {
                        throw ex;
                    }
                }
            }
        }

        public static ILogger GetLog()
        {
            return log;
        }

        public static ILogger GetLog(Type type)
        {
            return log;
        }

        public static ILogger GetLog(string category)
        {
            return log;
        }

        public static ILogger GetLog(string category, string subCategory)
        {
            return log;
        }
    }
}
